// pages/user/index.js
const utils = require('../../utils/util.js');
var app=getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabs: ["我发起的", "我参与的"],
        activeIndex: 0,
        sliderOffset: 0,
        sliderLeft: 0,
        icon60: '',
        pollList:false,
        joinList:false
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {


        var that = this;
        var $this = this;
        wx.getSystemInfo({
            success: function (res) {

                console.log(res);

                that.setData({
                    sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
                    sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
                });
            }
        });


        utils.geturl({
            "handler": "Home",
            "method":"myFq",
            'token': app.globalData.token
        }, function (res) {
            if (res.code==200) {
                $this.setData({
                    "pollList": res.data.list,
                });
            }
        });


        utils.geturl({
            "handler": "Home",
            "method":"myJoin",
            'token': app.globalData.token
        }, function (res) {
            if (res.code==200) {
                $this.setData({
                    "joinList": res.data.list,
                });
            }
        });


    },
    tabClick: function (e) {
        console.log('hi......')
        console.log(e)
        console.log(e.currentTarget.id)

        var $this = this;

        this.setData({
            sliderOffset: e.currentTarget.offsetLeft,
            activeIndex: e.currentTarget.id
        });

        if (e.currentTarget.id == 0){
            utils.geturl({
                "handler": "Home",
                "method":"myFq",
                'token': app.globalData.token
            }, function (res) {
                if (res.code==200) {
                    $this.setData({
                        "pollList": res.data.list,
                    });
                }
            });
        }else{
            utils.geturl({
                "handler": "Home",
                "method":"myJoin",
                'token': app.globalData.token
            }, function (res) {
                if (res.code==200) {
                    $this.setData({
                        "joinList": res.data.list,
                    });
                }
            });
        }


    },


    addclick: function () {

        wx.showToast({
            title: '开发中....',
            icon: "none"
        });

        // wx.navigateTo({
        //     url: '/pages/product/list?id=' + e.target.dataset.id,
        // })


    },


    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})